//获取登录状态
//解码decodeURIComponent
let userInfo = getCookie('userInfo') ? JSON.parse(decodeURIComponent(getCookie('userInfo'))) : null;
// console.log(userInfo)

// 获取到酒店ID
const hotalId = getUrlParam('id');

if (userInfo) {     // 登录状态
    //登录按钮状态
    document.querySelector('.resgist').innerHTML = `${userInfo.nickname} 欢迎`;
    //退出按钮
    document.querySelector('.out').addEventListener('click', () => {
        //删除cookie
        removeCookie('userInfo');
        //重新加载
        location.reload();
    })
} else {
    //登录按钮
    document.querySelector('.resgist').innerHTML = '登录';
    document.querySelector('.resgist').onclick = () => {
        location.href = 'login.html?callback=' + encodeURIComponent(location.href);
    }
}

// 获取酒店详细信息

axios.post(
    ' http://39.98.112.34:8000/hotel/detail',
    { id: hotalId }
).then((response) => {
    let res = response.data.data;
    // console.log(res)
    let html = "";
    res.rooms.forEach(item => {
        html += `
        <div class='hotal'>
            <div class="left">
                <img src="${res.photos}" alt="" width="130px" height="100px">
                <p>地址：${res.cityName}</p>
                <h3>${item.name}</h3>
            </div>
            <div class="right">
                <p>${item.name}</p>
                <p>可住2人</p>
                <p>大床无早</p>
                <p>不可取消</p>
                <p>￥${item.price}</p>
            <div class="sbox">
                <p><a href="javascrip:;">预定</a></p>
                <p><a href="javascrip:;">在线付</a></p>
            </div> 
        </div>
        `
    });
   
    document.querySelector('.top').innerHTML = html;
  let html2 = `<div class='des'><h3>酒店信息</h3>${res.content}</div>`;
  document.querySelector('.bottom').innerHTML = html2;

})